// pages/individualworkhistory/individualworkhistory.js
var util = require('../../utils/util.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inspectdata:[],
    dutyweektdata:[],
    winHeight:"",//窗口高度
    currentTab:0, //预设当前项的值
    scrollLeft:0, //tab标题的滚动条位置
    loading:1,
    flag:0,
    dutyTimes:0,
    dangerTimes:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let that=this
    wx.getSystemInfo( {
      success: function( res ) {
          var clientHeight=res.windowHeight,
              clientWidth=res.windowWidth,
              rpxR=750/clientWidth;
        var  calc=clientHeight*rpxR-180;
          console.log(calc)
          that.setData( {
              winHeight: calc
          });
      }
  });
  // 根据学校Id和UserId查询值周近一周从次数和发现异常次数
  wx.request({
    url: app.userUrl + '/WeChat/weChatSystem/getDutyWeekAndDangerCount',
    method: 'POST',
    data: {
      schoolId: app.globalData.departmentId,
      userId:app.globalData.userId 
    },
    dataType: 'json',
    success: res => {
      console.log(res.data);
      let dutyTimes = res.data.dutyTimes;
      let dangerTimes = res.data.dangerTimes
      this.setData({
        dutyTimes: dutyTimes,
        dangerTimes: dangerTimes
       })
     }
   })

    wx.request({
      url: app.userUrl + '/WeChat/weChatSystem/getInspectConditionForUser',
      method: 'POST',
      data: {
        schoolId: app.globalData.departmentId,
        userId:app.globalData.userId 
        // app.globalData.userId,
        
      },
      dataType: 'json',
      success: res => {
        console.log(res.data);
        res.data.map((item,index)=>{
          item.createTime=item.createTime.substr(5, 11)
        })
        this.setData({
          inspectdata:res.data
        })
      }
    })

    wx.request({
      url: app.userUrl + '/WeChat/weChatSystem/getDutyWeekConditionForUser',
      method: 'POST',  
      data: {
        schoolId:app.globalData.departmentId,
        userId:app.globalData.userId,  
      },
      dataType: 'json',
      success: res => {
        this.setData({
         dutyweektdata:res.data,
         loading:0,
         flag:0
        })
      }
    })
  },

 /**
  * 查询所有值周记录
  */
 alldutyWeek:function(){
  this.setData({
    loading:1,
   })
  wx.request({
    url: app.userUrl + '/WeChat/weChatSystem/getDutyWeekConditionAll',
    method: 'POST',
    data: {
      schoolId: app.globalData.departmentId,
      userId:app.globalData.userId 
    },
    dataType: 'json',
    success: res => {
      this.setData({
       dutyweektdata:res.data,
       loading:0,
       flag:1
      })
     }
   })
 },

  todetail:function(e){
console.log(e);

var data=JSON.stringify(e.currentTarget.dataset.item)
wx.navigateTo({
  url: '/pages/individualhistorydetail/index?data='+data,
})


},
showQuestionModal:function(e

){

let item=e.currentTarget.dataset.item
console.log(e, item);
  this.setData({
    boxshow:'block',
    bixdata:item
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  switchTab:function(e){
    this.setData({
        currentTab:e.detail.current
    });
    this.checkCor();
},
// 点击标题切换当前页时改变样式
swichNav:function(e){
    var cur=e.target.dataset.current;
    if(this.data.currentTaB==cur){return false;}
    else{
        this.setData({
            currentTab:cur
        })
    }
},
//判断当前滚动超过一屏时，设置tab标题滚动条。
checkCor:function(){
  if (this.data.currentTab>4){
    this.setData({
      scrollLeft:300
    })
  }else{
    this.setData({
      scrollLeft:0
    })
  }
},


})